/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */
package com.ykht.proj.coupon.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ykht.proj.common.security.util.SecurityUtils;
import com.ykht.proj.coupon.entity.CnCollection;
import com.ykht.proj.coupon.entity.CnCouShop;
import com.ykht.proj.coupon.mapper.CnCollectionMapper;
import com.ykht.proj.coupon.mapper.CnCouShopMapper;
import com.ykht.proj.coupon.service.CnCollectionService;
import com.ykht.proj.coupon.vo.CnCollectionPageReq;
import com.ykht.proj.coupon.vo.CnCollectionPageResp;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 收藏表
 *
 * @author proj code generator
 * @date 2020-11-16 17:00:21
 */
@RequiredArgsConstructor
@Service
public class CnCollectionServiceImpl extends ServiceImpl<CnCollectionMapper, CnCollection> implements CnCollectionService {
	private final CnCollectionMapper cnCollectionMapper;
	private final CnCouShopMapper cnCouShopMapper;
	@Override
	public IPage<CnCollectionPageResp> opPage(Page page, CnCollectionPageReq query) {
		IPage<CnCollectionPageResp> resp = cnCollectionMapper.opPage(page, query);
		resp.getRecords().stream().forEach(o->{
			List temp= cnCouShopMapper.selectList(Wrappers.lambdaQuery(CnCouShop.class).eq(CnCouShop::getShopId,o.getShopId()));
			o.setCouponCount(temp.size()+o.getTyCouponCount());
		});
		return resp;
	}

	@Override
	public List<String> opList(Page page) {
		Long id= SecurityUtils.getPersonId();
		return cnCollectionMapper.opPicList(page, id);
	}
}
